<template>
  <div class="about">
    <draggable
        :list="dragArr"
        ghost-class="ghost"
        :force-fallback="true"
        chosen-class="chosenClass"
        animation="300"
        @start="onDragStart"
        @end="onDragEnd"
        :sort="true"
        handle=".drag"
        item-key="id"
    >
      <template #item="{ element, index }">
        <div :class="element.state == 1 ? 'item1 item' : 'item'">
          <i><el-checkbox @change="checkoutChange(element, index)" v-model="element.state" size="large" :label="element.name" :true-label="1" :false-label="0"/></i>
          <i>{{element}}</i>
          <i>{{ index + 1 }}</i>
          <i class="drag">拖动</i>
        </div>
      </template>
    </draggable>
  </div>
</template>

<script setup>
import draggable from "vuedraggable";
import { reactive ,ref,defineEmits,defineProps } from "vue";

let dragArr = reactive([[
  {
    name: "张三",
    state: "0",
    id: 1,
  },
  {
    name: "李四",
    state: "0",
    id: 2,
  },
  {
    name: "王五",
    state: "0",
    id: 3,
  },
  {
    name: "赵六",
    state: "0",
    id: 4,
  },
  {
    name: "AK、dadada",
    state: "0",
    id: 5,
  },
]]);

// 复选框勾选
const checkoutChange = (element, index) => {
  console.log("checkoutChange", element, index);
};
// 拖动前
const onDragStart = () => {
  console.log("onDragStart");
};
// 拖动后
const onDragEnd = () => {
  console.log("onDragEnd");
};
</script>
<style lang="scss">
.notice-dialog1 {
  padding: 0 12px;
  border-radius: 15px;
  .my-header {
    position: relative;
    h4 {
      text-align: center;
      height: 30px;
    }
    .el-icon {
      position: absolute;
      top: 2px;
      right: -10px;
      cursor: pointer;
    }
    .spanTip {
      font-size: 14px;
      color: #999;
    }
  }

  .item {
    padding: 6px 10px;
    width: 46%;
    display: inline-flex;
    justify-content: space-between;
    margin: 0 0.5%;
    background-color: #f6f8fa;
    border-radius: 5px;
    line-height: 42px;

    i:nth-child(1) {
      width: 70%;
      height: 42px;
      line-height: 46px;
    }
    i:nth-child(2) {
      width: 12%;
      height: 16px;
      line-height: 16px;
      margin: auto 0;
      text-align: center;
      text-decoration: underline;
      border-left: 1px solid #ccc;
      border-right: 1px solid #ccc;
    }
    i:nth-child(3) {
      width: 8%;
      height: 42px;
      line-height: 42px;
      text-decoration: underline;
      padding-left: 20px;
      img {
        width: 15px;
        height: 20px;
        margin-top: 10px;
      }
    }

    .el-checkbox.el-checkbox--large {
      height: 7%;
    }
    .el-checkbox__input.is-checked .el-checkbox__inner {
      background-color: #114ed9;
      border-color: #114ed9;
    }
    .el-checkbox__input.is-checked + .el-checkbox__label {
      color: #114ed9;
    }
  }
  .item1 {
    background-color: #ffffff;
    box-shadow: 0 0 10px #0000001a;
    border-left: solid 2px #114ed9;
    width: 45.8%;
    line-height: 40px;
  }

  .drag {
    cursor: move;
  }

  .item + .item {
    margin-top: 20px;
  }

  .ghost {
    border: solid 1px rgb(19, 41, 239) !important;
  }

  .chosenClass {
    background-color: #eee;
    opacity: 1;
    border: solid 1px red;
  }
}
.notice-dialog1 .el-dialog__header {
  border-bottom: 1px solid #f6f6f6;
  margin-right: 0;
}
.notice-dialog1 .el-dialog__body {
  height: 300px;
  overflow: auto;
}
.notice-dialog1 .el-dialog__body::-webkit-scrollbar {
  display: none;
}
.notice-dialog1 .el-dialog__footer {
  border-top: 1px solid #f6f6f6;
  text-align: center;
  padding-top: 20px;
}
</style>
